SWAGOLX.EXE (c) 1993 GDSOFT ALL RIGHTS RESERVED 00004 1 05-25-9408:02ALL STEVE ROGERS Complex Math Unit SWAG9405 18 ₧ π{Just for grins, here's a complex number unit I wrote come time back:}ππunit complex;π(*π polar/rectangular conversions and complex mathπ Steve Rogers, ~1993π*)ππ{----------------------}πinterfaceππtypeπ tComplex=recordπ r, { real component }π x { imaginary component }π : real;π end;ππprocedure r2p(var r,p : tComplex);πprocedure p2r(var p,r : tComplex);πprocedure c_add(var c1,c2,c3 : tComplex);πprocedure c_sub(var c1,c2,c3 : tComplex);πprocedure c_mult(var c1,c2,c3 : tComplex);πprocedure c_div(var c1,c2,c3 : tComplex);ππimplementationππconstπ RADS=0.0174532; { degree to radian conversion constant }ππ{----------------------}πprocedure r2p(var r,p : tComplex);π{ returns polar in degrees in p, given rectangular in r }πbeginπ p.r:= sqrt(sqr(r.r)+sqr(r.x));π p.x:= arctan(r.x/r.r)/RADS;πend;ππ{----------------------}πprocedure p2r(var p,r : tComplex);π{ returns rectangular in r, given polar in degrees in p }πbeginπ r.r:= p.r*cos(p.x*RADS);π r.x:= p.r*sin(p.x*RADS);πend;ππ{----------------------}πprocedure c_add(var c1,c2,c3 : tComplex);π{ adds c2 to c1, places result in c3 }πbeginπ c3.r:= c1.r+c2.r;π c3.x:= c1.x+c2.x;πend;ππ{----------------------}πprocedure c_sub(var c1,c2,c3 : tComplex);π{ subtracts c2 from c1, places result in c3 }πbeginπ c3.r:= c1.r-c2.r;π c3.x:= c1.x-c2.x;πend;ππ{----------------------}πprocedure c_mult(var c1,c2,c3 : tComplex);π{ multiplies c1 by c2, places result in c3 }πbeginπ c3.r:= (c1.r*c2.r)-(c1.x*c2.x);π c3.x:= (c1.r*c2.x)+(c1.x*c2.r);πend;ππ{----------------------}πprocedure c_div(var c1,c2,c3 : tComplex);π{ divides c1 by c2, places result in c3 }πvarπ p1,p2,p3 : tComplex;ππbeginπ r2p(c1,p1); { convert c1 to polar form }π r2p(c2,p2); { convert c2 to polar form }π p3.r:= p1.r/p2.r; { divide real component }π p3.x:= p1.x-p2.x; { subtract imaginary component }π if (p3.x<0) then p3.x:= p3.x+180; { Pretty it up }π p2r(p3,c3); { convert c3 back to rectangular }πend;π 2 05-25-9408:24ALL JUHANI KAUKORANTA Trig & hyperbolic functioSWAG9405 24 ₧ {πMSGID: 2:228/406 68DEA672πHere is the unit of trigonometric and hyperbolicπreal functions:π}ππUNIT trighyp;π{ Juhani Kaukoranta, Sysop of Pooki MBBS, Finlandπ Pooki MBBS 358-82-221 782 }ππINTERFACEππFUNCTION TAN(x:Real):Real;πFUNCTION COT(x:Real): Real;πFUNCTION SEC(x:Real): Real;πFUNCTION COSEC(x:Real): Real;πFUNCTION SINH(x:Real): Real;πFUNCTION COSH(x:Real): Real;πFUNCTION TANH(x:Real): Real;πFUNCTION COTH(x:Real): Real;πFUNCTION SECH(x:Real): Real;πFUNCTION COSECH(x:Real): Real;πFUNCTION ARCSIN(x:Real):Real;πFUNCTION ARCCOS(x:Real):Real;πFUNCTION ARCCOT(x:Real): Real;πFUNCTION ARCSEC(x:Real): Real;πFUNCTION ARCCOSEC(x:Real): Real;πFUNCTION ARCSINH(x:Real): Real;πFUNCTION ARCCOSH(x:Real): Real;πFUNCTION ARCTANH(x:Real): Real;πFUNCTION ARCCOTH(x:Real): Real;ππIMPLEMENTATIONππFUNCTION TAN(x: Real): Real;π{ argument x is in radians }πBEGINπ TAN := SIN(x)/COS(x);πEND;ππFUNCTION COT(x:Real): Real;π{ cotangent, x is in radians }πBEGINπ COT := 1/TAN(x);πEND;ππFUNCTION SEC(x:Real): Real;π{ secant, x is in radians }πBEGINπ SEC := 1/COS(x);πEND;ππFUNCTION COSEC(x:Real): Real;π{ cosecant, x is in radians }πBEGINπ COSEC := 1/SIN(x);πEND;ππFUNCTION SINH(x:real):Real;π{ hyperbolic sin }πBEGINπ SINH := (EXP(x)-EXP(-x))/2;πEND;ππFUNCTION COSH(x:Real): Real;π{ hyperbolic cos }πBEGINπ COSH := (EXP(x)+EXP(-x))/2;πEND;ππFUNCTION TANH(x:Real): REAL;π{ hyperbolic tan }πBEGINπ TANH := SINH(x)/COSH(x);πEND;ππFUNCTION COTH(x: Real): Real;π{ hyperbolic cotangent }πBEGINπ COTH :=SINH(x)/COSH(x);πEND;ππFUNCTION SECH(x:Real): Real;π{ hyperbolic secant }πBEGINπ SECH := 1/COSH(x);πEND;ππFUNCTION COSECH(x:Real): Real;π{ hyperbolic cosecant }πBEGINπ COSECH := 1/SINH(x);πEND;ππFUNCTION ARCSIN(x:Real):Real;π{ inverse of sin, return value is in radians }πBEGINπ IF ABS(x)=1.0 THENπ ARCSIN := x*Pi/2π ELSEπ ARCSIN := ARCTAN(x/SQRT(-SQR(x)+1));πEND;ππFUNCTION ARCCOS(x:Real):Real;π{ inverse of cos, return value is in radians }πBEGINπ IF x = 1.0 THENπ ARCCOS := 0π ELSE IF x = -1.0 THENπ ARCCOS :=Piπ ELSEπ ARCCOS := -ARCTAN(x/SQRT(-SQR(x)+1))+Pi/2;πEND;ππFUNCTION ARCCOT(x:Real): Real;π{ inverse of cot, return value is in radians }πBEGINπ ARCCOT := ARCTAN(1/x);πEND;ππFUNCTION ARCSEC(x:Real): Real;π{ inverse of secant, return value is in radians }πBEGINπ ARCSEC := ARCCOS(1/x);πEND;ππFUNCTION ARCCOSEC(x:Real): Real;π{ inverse of cosecant, return value is in radians }πBEGINπ ARCCOSEC := ARCSIN(1/x);πEND;ππFUNCTION ARCSINH(x:Real): Real;π{ inverse of hyperbolic sin }πBEGINπ ARCSINH := LN(x + SQRT(x*x+1));πEND;ππFUNCTION ARCCOSH(x:Real): Real;π{ inverse of hyperbolic cos}πBEGINπ ARCCOSH := LN(x + SQRT(x*x-1));πEND;ππFUNCTION ARCTANH(x:Real): Real;π{ inverse of hyperbolic tan }πBEGINπ ARCTANH := LN((1+x)/(1-x))/2;πEND;ππFUNCTION ARCCOTH(x:Real): REAL;π{ inverse of hyperbolic cotangent }πBEGINπ ARCCOTH := LN((x+1)/(x-1))/2;πEND;ππEND. { of unit }π 3 05-26-9406:18ALL RUUD KUCHLER Prime Numbers SWAG9405 13 ₧ {πJT>Does anyone know of anyway to code a prime number generator?? I've hadπJT>some ideas, but none so far that have worked... I am just learning PascalπJT>right now, so I do need some help... Any would be appreciated becauseπJT>this is for a class assignment!! ThankXππTry this:ππ------ take scissors and cut here :-) ------------------------ }ππprogram priem;ππ{Program creates prime numbers.ππWorking of the program:π- an array is created where found prime numbers are stored.πChecking whether a number is prime:π- the number is checked with the previously found prime numberπif it is primeπ- if it is prime it is stored in the array and printed}ππconstπmaxpriems=10000;ππtypeπpriemarrtype=array[1..maxpriems] of longint; {array to store primes}ππvarπpriemarr: priemarrtype;πnrofpriem: word;πnumber, divider: longint;πisapriemnumber: boolean;ππbegin {priem}πnumber:=1;πnrofpriem:=0; {number of prime numbers already found}πwhile(nrofpriem<maxpriems) doπbeginπinc(number);πisapriemnumber:=true;πdivider:=1;πwhile (isapriemnumber) and (divider<=nrofpriem) doπbeginπif (number mod priemarr[divider]=0)π{calculate "remains" of division}πthen isapriemnumber:=false {no prime}πelse inc(divider) {get next prime}πend; { not (isapriemnumber) or (divider>nrofpriem) }πif (isapriemnumber) thenπbegin {a prime number is found}πinc(nrofpriem);πpriemarr[nrofpriem]:=number; {store it in the array}πwriteln('prime number ',nrofpriem:5,' found is:π',priemarr[nrofpriem]:8)πendπend; { nrofpriem>=maxpriems }πend. {priem}ππ 4 05-26-9406:18ALL SCOTT STONE More Prime Numbers SWAG9405 6 ₧ πFunction CheckPrime(a : integer) : boolean;πVarπ x : integer;π y : integer;πBeginπ y:=0;π for x:=1 to (a div 2) do {Only #s up to half of a can be factors}π beginπ if (a mod x)=0 then y:=(y+1)π end;π if y=2 then checkprime:=true else checkprime:=false;π if a=1 then checkprime:=true;πEnd;ππYou see, only prime numbers have exactly two factors, themselves and one.πWith the exception of One. Therefore you have a specific IF for theπnumber one. One is prime, yet its only factor is one. I think - Is oneπprime or not? Anyway, remove that line if it isn't, the function will work.π